//
//  STAdmobEnum.swift
//  iPhone
//
//  Created by Toj on 4/3/23.
//

import Foundation
struct STAdmobAdState: OptionSet {
    public var rawValue: UInt
    public init(rawValue: UInt) {
        self.rawValue = rawValue
    }
    
    static var normal: STAdmobAdState { return STAdmobAdState(rawValue: 1<<0) }
    // 预加载: 闲置情况下预先加载下一次展示的内容
    static var preloading: STAdmobAdState { return STAdmobAdState(rawValue: 1<<1) }
    // 预加载完成: 准备完成等待展示
    static var preloaded: STAdmobAdState { return STAdmobAdState(rawValue: 1<<2) }
    // 加载中: 预加载未有完成, 需要现加载.
    static var loading: STAdmobAdState { return STAdmobAdState(rawValue: 1<<3) }
    // 加载完成: 加载完成等待展示.
    // 可能是从 preloaded变成loaded, 也可能是从loading变成loaded
    static var loaded: STAdmobAdState { return STAdmobAdState(rawValue: 1<<4) }
    // 展示中: 现加载/ 预加载广告显示中
    static var showing: STAdmobAdState { return STAdmobAdState(rawValue: 1<<5) }
    // 展示完成: 调用广告dismiss后退出显示
    static var showed: STAdmobAdState { return STAdmobAdState(rawValue: 1<<6) }
    
    var isPreload: Bool {
        return contains(.preloading) || contains(.preloaded)
    }
    
    var isLoading: Bool {
        return contains(.loading)
    }
    
    var isLoaded: Bool {
        return contains(.loaded)
    }
    var isShowed: Bool {
        return contains(.showing) || contains(.showed)
    }
}
